NexusPi Git Node
native/TCPHostInterface.h HEAD (592c826d) Text, 2.67 KB
T8b949e// Native-target KISS-over-TCP transport. A single-client TCP server bound
T8b949e// to 127.0.0.1, replacing the embedded firmware's USB-serial KISS channel
T8b949e// on Portduino-backed builds.
T8b949e//
T8b949e// Lifecycle mirrors Remote.h's WiFiServer pattern: one listening socket,
T8b949e// at most one active client, idle-timeout-driven reconnect. Second clients
T8b949e// are rejected immediately by accepting + close()ing them on the spot.
T8b949e//
T8b949e// Logs (RNS log callback, printf redirect) DO NOT pass through this
T8b949e// channel. They stay on Portduino's Serial (typically stdout). This keeps
T8b949e// the KISS byte stream clean of ASCII log content.
Tff7b72#Tff7b72ifndef NATIVE_TCP_HOST_INTERFACE_H
Tff7b72#Tff7b72define NATIVE_TCP_HOST_INTERFACE_H
Tff7b72#Tff7b72include T8b949e<cstdint>
Te6edf3namespace Te6edf3native_kiss_tcp Tb4b4b4{
T8b949e// Create the listening socket. Returns false if bind/listen failed; the
T8b949e// daemon should keep running anyway (no host connection just means no
T8b949e// external control, like an embedded board with no USB cable attached).
T8b949e//
T8b949e// `bind_public`: when false, bind only on 127.0.0.1 (loopback, the safe
T8b949e// default — no network exposure). When true, bind on 0.0.0.0 so remote
T8b949e// hosts on the same network can connect. Public binding has no auth or
T8b949e// encryption, so opt in only on trusted networks.
Tffa657bool Td2a8ffinitTb4b4b4(Tffa657uint16_t Te6edf3portTb4b4b4, Tffa657bool Te6edf3bind_publicTb4b4b4)Tb4b4b4;
T8b949e// Per-loop housekeeping. Should be called from the firmware's main loop
T8b949e// before draining bytes. Accepts any pending connection (or rejects it if
T8b949e// one is already active), and refills the internal RX buffer from the
T8b949e// kernel socket.
Tffa657void Td2a8ffpoll_acceptTb4b4b4(Tb4b4b4)Tb4b4b4;
T8b949e// Idle / dead-peer sweep. Drops the active client if it has gone silent
T8b949e// past the idle window. Safe to call from a periodic tick.
Tffa657void Td2a8ffcheck_activeTb4b4b4(Tb4b4b4)Tb4b4b4;
T8b949e// True if a client is currently attached and the connection looks healthy.
Tffa657bool Td2a8ffis_connectedTb4b4b4(Tb4b4b4)Tb4b4b4;
T8b949e// True if at least one byte is currently available to read. Calling
T8b949e// poll_accept() refills the buffer; available() does not block.
Tffa657bool Td2a8ffavailableTb4b4b4(Tb4b4b4)Tb4b4b4;
T8b949e// Non-blocking read of one byte from the staging buffer. Returns 0xC0
T8b949e// (KISS FEND) if no data is available — same fallback as Remote.h so an
T8b949e// accidental drain of an empty buffer yields a frame boundary rather
T8b949e// than spurious data.
Tffa657uint8_t Td2a8ffreadTb4b4b4(Tb4b4b4)Tb4b4b4;
T8b949e// Best-effort single-byte send to the active client. Drops the byte if
T8b949e// no client is attached or the send fails (treats partial / EAGAIN as
T8b949e// a fatal disconnect, since the host can't recover a half-sent frame).
Tffa657void Td2a8ffwriteTb4b4b4(Tffa657uint8_t Te6edf3byteTb4b4b4)Tb4b4b4;
T8b949e// Close any active client and the listening socket. Used by the deferred-
T8b949e// reboot path so the re-exec'd process can re-bind the same port without
T8b949e// waiting on the kernel's TIME_WAIT.
Tffa657void Td2a8ffshutdownTb4b4b4(Tb4b4b4)Tb4b4b4;
Tb4b4b4} T8b949e// namespace native_kiss_tcp
Tff7b72#Tff7b72endif
Served by rngit 1.5.2 - Generated in 0.01s